package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.Ware;
import com.zoo.diannaopeijian.mapper.WareMapper;
import com.zoo.diannaopeijian.service.WareService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品服务实现类
 */
@Service
public class WareServiceImpl implements WareService {
    @Resource
    private WareMapper wareMapper;

    @Override
    public List<Ware> getWare(Ware ware) {
        return wareMapper.select(ware);
    }

    @Override
    public List<Ware> getWareWithPage(Page page, Ware ware) {
        if (page != null) {
            page.onPage();
        }

        return getWare(ware);
    }

    @Override
    public List<Ware> getFuzzyWare(Ware ware) {
        return wareMapper.selectFuzzyWare(ware);
    }

    @Override
    public List<Ware> getFuzzyWareWithPage(Page page, Ware ware) {
        if (page != null) {
            page.onPage();
        }

        return getFuzzyWare(ware);
    }

    @Override
    public boolean addWare(Ware ware) {
        if (CheckUtil.allNullBeanCheck(ware)) {
            return true;
        }
        return wareMapper.insertSelective(ware) == 1;
    }

    @Override
    public boolean deleteWareById(Integer wareid) {
        if (wareid == null) {
            throw new NullPointerException();
        }
        return wareMapper.deleteByPrimaryKey(wareid) == 1;
    }

    @Override
    public boolean updateWare(Ware ware) {
        if (CheckUtil.allNullBeanCheck(ware)) {
            return true;
        }
        return wareMapper.updateByPrimaryKeySelective(ware) == 1;
    }

    @Override
    public List<Ware> getWareByNameAndBarCode(Ware ware) {
        return wareMapper.selectFuzzyOrWare(ware);
    }
}
